package com.shamoa.springbootredis.demos.exMessageListener;

import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;

/**
 * @author zy
 * @version 1.0
 * @date 2024/3/24 15:28
 * @description
 **/
@Component
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {

    public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        String channel = new String(message.getChannel());
        System.out.println("消息的频道为: " + channel);
        System.out.println("监听到过期消息: " + new String(message.getBody()));
        System.out.println("失效key为: " + message.toString());
    }


}
